package com.javasm.service.JINXIAOService.impl;

import com.javasm.commons.basic.BaseServiceImpl;
import com.javasm.entity.JINXIAOEntity.SysMenu;
import com.javasm.service.JINXIAOService.SysMenuService;
import com.javasm.dao.JINXIAODao.SysMenuDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuDao, SysMenu> implements SysMenuService {


    @Autowired
    private SysMenuDao sysMenuDao;

    @Override
    public List<SysMenu> queryMenuList(String menuIds) {
        List menulist= Arrays.asList(menuIds.split(","));
        log.info("menulist:{}",menulist);
        List<SysMenu> sysMenus = sysMenuDao.querymenuByLevel(0,menulist);
        List<SysMenu> subMenus = sysMenuDao.querymenuByLevel(1,menulist);
        sysMenus.forEach(sysMenu -> {
            List<SysMenu> subMenuList = subMenus.stream().filter(subMenu -> subMenu.getPid().equals(sysMenu.getId())).collect(Collectors.toList());
            sysMenu.setSubMenus(subMenuList);
        });
        return sysMenus;
    }
}